import com.zjw.entity.Note;
import com.zjw.entity.Page;
import com.zjw.service.NoteService;
import com.zjw.service.impl.NoteServiceImpl;

import java.util.Date;
import java.util.InputMismatchException;
import java.util.Scanner;

/**
 * @projectName: note
 * @package: PACKAGE_NAME
 * @className: Test1
 * @author: 翟
 * @date: 2025/4/3 14:16
 */

public class Test1 {
    public static void main(String[] args) {
        NoteService noteService = new NoteServiceImpl();
        Scanner input = new Scanner(System.in);
        do {
            System.out.println("1.写笔记 2.查看笔记 0.退出");
            String choice = input.next().trim();
            int choiceNum = 0;
            try {
                choiceNum = Integer.parseInt(choice);
            } catch (NumberFormatException e) {
                System.out.println("输入的不为数字，请重新输入");
                continue;
            }

            switch (choiceNum) {
                case 1:
                    System.out.println("请输入笔记标题：");
                    String title = input.next().trim();
                    System.out.println("请输入笔记内容：");
                    String content = input.next();
                    noteService.addNote(new Note(title, new Date(), content));
                    break;
                case 2:
                    Page<Note> page = new Page<>();
                    page.setTotalCount(noteService.getNoteCount());
                    int num = 0;
                    do {
                        page.setData(noteService.getNoteByPage(page.getCurrPageNo(), page.getPageSize()));
                        page.getData().forEach(System.out::println);
                        System.out.println("当前页数/总页数：" + page.getCurrPageNo() + "/" + page.getTotalPageCount());
                        System.out.println("1.阅读笔记 2.上一页 3.下一页 0.返回上一级");
                        String choicePage = input.next().trim();
                        int choicePageNum = 0;
                        try {
                            choicePageNum = Integer.parseInt(choicePage);
                        } catch (NumberFormatException e) {
                            System.out.println("输入的不为数字，请重新输入");
                            continue;
                        }
                        switch (choicePageNum) {
                            case 1:
                                System.out.println("请输入阅读笔记的编号：");
                                int id = 0;
                                try {
                                    id = input.nextInt();
                                } catch (InputMismatchException e) {
                                    System.out.println("输入有误！！！");
                                    break;
                                }
                                Note note = noteService.getNoteById(id);
                                System.out.println("笔记标题为：" + note.getNoteTitle());
                                System.out.println("笔记内容为："+ note.getNoteContent());
                                System.out.println("笔记创建日期为："+ note.getNoteCreationDate());
                                break;
                            case 2:
                                page.setCurrPageNo(page.getCurrPageNo() - 1);
                                break;
                            case 3:
                                page.setCurrPageNo(page.getCurrPageNo() + 1);
                                break;
                            case 0:
                                num = 1;
                                break;
                            default:
                                System.out.println("没有该选项，请重新输入");
                                break;
                        }
                        System.out.println();
                    } while (num == 0);
                    System.out.println();
                    break;
                case 0:
                    System.exit(0);
                default:
                    System.out.println("没有该选项，请重新输入");
                    break;
            }
            System.out.println();
        } while (true);
    }
}
